$(document).ready(function(){
	
	$('.data-table').dataTable({
		"bJQueryUI": true,
		"sPaginationType": "full_numbers",
		"sDom": '<""l>t<"F"fp>',
		"fnDrawCallback": function () {
			taskStatisticsDetail();
		}
	});
	
	function taskStatisticsDetail() {
		$(".btn-info").each(function(){
			$(this).click(function() {
				var taskType=$(this).attr("id");
				$("#config-modal").modal({
					show : true,
					keyboard : true
				});
				$.get("taskStatisticsDetail?taskType="+taskType, function(data) {
					var json = JSON.parse(data);
					$("#taskType_modal").html(json.taskType);
					$("#sumTaskNum_modal").html(json.sumTaskNum);
					$("#notFinishTaskNum_modal").html(json.notFinishTaskNum);
					$("#waitTaskNum_modal").html(json.waitTaskNum);
					$("#waitRate_modal").html(json.waitRate);
					$("#runningTaskNum_modal").html(json.runningTaskNum);
					$("#runningRate_modal").html(json.runningRate);
					$("#finishTaskNum_modal").html(json.finishTaskNum);
					$("#finishRate_modal").html(json.finishRate);
					$("#successTaskNum_modal").html(json.successTaskNum);
					$("#successRate_modal").html(json.successRate);
					$("#failureTaskNum_modal").html(json.failureTaskNum);
					$("#failureRate_modal").html(json.failureRate);
					$("#minWaitDuration_modal").html(json.minWaitDuration);
					$("#maxWaitDuration_modal").html(json.maxWaitDuration);
					$("#avgWaitDuration_modal").html(json.avgWaitDuration);
					$("#minComputeDuration_modal").html(json.minComputeDuration);
					$("#maxComputeDuration_modal").html(json.maxComputeDuration);
					$("#avgComputeDuration_modal").html(json.avgComputeDuration);
				});
			});
		})
	}
	
	$('input[type=checkbox],input[type=radio],input[type=file]').uniform();
	
	$('select').select2();
	
	$("span.icon input:checkbox, th input:checkbox").click(function() {
		var checkedStatus = this.checked;
		var checkbox = $(this).parents('.widget-box').find('tr td:first-child input:checkbox');		
		checkbox.each(function() {
			this.checked = checkedStatus;
			if (checkedStatus == this.checked) {
				$(this).closest('.checker > span').removeClass('checked');
			}
			if (this.checked) {
				$(this).closest('.checker > span').addClass('checked');
			}
		});
	});	
});

